(defun say-hello ()
    "Say Hello to the whole world. "
    (message "Hello World"))
(defun say-hello (greeting)
  "Say GREETING to user, and kee message."
  (message greeting)
  )
(say-hello "Hello World")
(defun my/sum (num1 num2)
  "Sum of two integer NUM1 and NUM2 and return integer."
  (+ num1 num2)
  )
(my/sum 1 3)
(my/sum (my/sum 3 4) (my/sum (my/sum 5 6) 7))
會先計算 (my/sum 5 6),再計算 (my/sum 11 7) ...
(defun times-3 (x) (* x 3))
(defun times-4 (x) (* x 4))
(defun multiples (multi-func max-num)
	(dotimes (x max-num)
		(print (format "%d: %d" x (funcall multi-func x))))
	)
(multiples #'times-3 10)
(multiples #'times-4 10)
times-3 跟 times-4
(dotimes x max-num) 是 for (x = 0; x < max-num; x++) 的意思(funcall 'times-3 8) 就會等於 24
 
(let ((max 10))
  (dotimes (x max)
    (print (format "%d" x))))
會印出 0 ... 9
(lambda (x) (* x x x))
((lambda (x) (* x x x)) 5)
(mapcar* 'times-3 (4 5 6))
結果會是 (12 15 18)
;;
;; if statement
;;
(defun odd-or-even (x)
	(if (= 0 (% x 2))
		"even"
		"odd"))
(odd-or-even 3)
(odd-or-even 4)
;;
;; condition, or switch case
;;
(defun pick-word (n)
	(cond
	 ((= n 1) "gold")
	 ((= n 2) "silver")
	 ((= n 3) "bronz")
	 (t "winner")))
(pick-word 3)
(pick-word 33)
;;
;; for-loop
;;
(loop for x from 1 to 10
			do (print x))
;;
;; dotimes
;;
(dotimes (y 12)
	(print y))
;;
;; recursive
;;
(defun factorial (n)
	(if (< n 1)
	1
	(* n (factorial (- n 1)))))
(factorial 3)
(factorial 10)
相關簡報請看 我的部落格